<template>
  <div class="appraisal">
    <div class="box" v-for="(item, index) in appraisalList" :key="index">
      <div class="appraisal-box">
        <div class="box-head">
          <van-icon name="smile-o" color="#ee0a24" size="0.8rem" />
        </div>
        <div class="box-center">
          <p class="box-center-title">{{ item.title }}?</p>
          <p class="box-center-text">
            {{ item.info }}
          </p>
        </div>
        <div class="box-footer">
          <span
            class="box-footer-img"
            v-for="(ele, num) in item.headPic"
            :key="num"
          >
            <img :src="ele" alt="" />
          </span>
          <span> {{ item.upData }} </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from "../../../api";
import loading from "../pullLoading/pullLoading.js";
import { Dialog } from "vant";

export default {
  name: "Appraisal",
  data() {
    return {
      appraisalList: [],
      page: 1,
    };
  },
  mounted() {
    this.http(this.page);

    window.addEventListener("scroll", this.handleScroll);
  },
  methods: {
    http(page) {
      api.gotoAppraisal(page).then((res) => {
        // console.log(res.data);
        // this.houseList = res.data.list;
        this.appraisalList = [...this.appraisalList, ...res.data.list];
        this.page++;
      });
    },
    handleScroll() {
      if (this.page < 4) {
        loading(this.page, this.http);
      } else {
        Dialog({ message: "期待大家更多的评论..." });
        this.page = 1;
        window.removeEventListener("scroll", this.handleScroll);
      }
    },
  },
  destroyed() {
    window.removeEventListener("scroll", this.handleScroll);
  },
};
</script>

<style lang="less">
.box {
  margin-top: 0.7rem;
}
.appraisal-box {
  background-color: hsl(0, 60%, 98%);
  border: 1px solid #ccc;
  box-shadow: 0 0 0.2rem #ccc;
  border-radius: 0.1rem;
  width: 70%;
  margin: 0 auto;
  padding: 0 0.5rem;
}
.box-head {
  margin-top: 0.58rem;
}
.box-center {
  margin-top: 0.26rem;
  font-size: 13px;
  color: rgba(000, 000, 000, 0.8);
  .box-center-title {
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .box-center-text {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
}
.box-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0.3rem 0 0.3rem 0;
  font-size: 13px;
  color: rgba(000, 000, 000, 0.8);
  // display: flex;
  // justify-content: space-between;
  .box-footer-img {
    position: relative;
    left: -0.2rem;
    display: inline-block;
    border-radius: 50%;
    background-color: blue;
    width: 0.5rem;
    height: 0.5rem;
    overflow: hidden;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>>